<template>
    <div>
        商户地址:<select v-model="ps.id">
                        <option value="">请选择</option>
                        <option :value="o.cid" v-for="o in lie" :key="o.cid">{{ o.cname }}</option>
                    </select>
        门店名称:<input type="text" v-model="ps.name">
        <input type="button" value="查询" @click="show()">
          <table class="table table-border">
            <tbody>
                <tr>
                    <td>门店名称</td>
                    <td>分店名称</td>
                    <td>商户地址</td>
                    <td>图片</td>
                    <td>客服电话</td>
                    <td>门店状态</td>
                    <td>门店介绍</td>
                    <td>入住须知</td>
                    <td>交通信息</td>
                    <td>操作</td>
                </tr>
                <tr  v-for="o in data.plist" :key="o.mid">
                    <td>{{o.mname}}</td>
                    <td>{{o.fen}}</td>
                    <td>{{o.cname}}</td>
                    <td> <img :src="o.tu" width="100" height="100"></td>
                    <td>{{o.phone}}</td>
                    <td>{{o.flag==1?"启用":"禁用"}}</td>
                    <td>{{o.js}}</td>
                    <td>{{o.xu}}</td>
                    <td>{{o.jt}}</td>
                    <td><input type="button" value="删除" @click="Delete(o.mid,true)"></td>
                </tr>
            </tbody>
        </table>
        一共<span>{{data.count}}</span>条
        每页<span>{{ ps.pagesize }}</span>条
        共<span>{{ps.pageindex}}/{{data.pagecount}}</span>页
        <input type="button" value="首页" @click="page(1)">
        <input type="button" value="上一页" @click="page(ps.pageindex-1)">
        <input type="button" :value="o" v-for="o in data.pagecount" :key="o" @click="page(o)">
        <input type="button" value="下一页" @click="page(ps.pageindex+1)">
        <input type="button" value="尾页" @click="page(data.pagecount)">
        <input type="number" v-model="ps.pageindex">
        <input type="button" value="跳转" @click="page(ps.pageindex)">
        <select @change="pa">
            <option :value="o" v-for="o in l" :key="o">每页{{o}}条</option>
        </select>
    </div>
</template>

<script setup lang="ts">
import{onMounted, ref} from 'vue'
import {useRoute,useRouter} from 'vue-router'
import axios from 'axios';
import moment from 'moment';
const route = useRoute()
const router = useRouter()
let l:any = ref([2,3,4])
const pa = (e:any)=>{
    ps.value.pageindex = 1
    ps.value.pagesize = e.target.value
    show()
}
const page = (val:any)=>{
    if(val>=1&&val<=data.value.pagecount)
    {
        ps.value.pageindex = val
    }
    show()
}
let ps:any = ref({
    name:'',
    id:'',
    pageindex:1,
    pagesize:2
})
let data:any = ref({
    plist:[],
    counr:'',
    pagecount:''
})
let lie:any = ref({    
})
onMounted(()=>{
    show()
    lieshow()
})
const lieshow=()=>{
    axios({
        url:'https://localhost:7029/api/Men/Chengs',
        method:'get'
    })
    .then(res=>{
        lie.value = res.data
    })
}
const show=()=>{
    axios({
        url:'https://localhost:7029/api/Men/FenDTO',
        method:'get',
        params:ps.value
    })
    .then(res=>{
        Object.assign(data.value,res.data)
    })
}
const Delete=(id:any,z:any)=>{
      if(!confirm("确定要删除吗"))
      {

      }
    axios({
        url:'https://localhost:7029/api/Men/Delete',
        method:'put',
        params:{
            id:id,
            z:z
        }
    })
    .then(res=>{
        if(res.data>0)
        {
            alert('删除成功')
            show()
        }
        else
        {
             alert('删除失败')
             return;
        }
    })
}
</script>

<style scoped>

</style>